//------------------------------------------------------------------------------
#include <QtGui>
#include <QTimeEdit>
#include "CTimeEditDelegate.h"
//------------------------------------------------------------------------------
CTimeEditDelegate::CTimeEditDelegate(QObject *parent) : QItemDelegate(parent)
{
}
//------------------------------------------------------------------------------
QWidget * CTimeEditDelegate::createEditor(	QWidget *parent, const QStyleOptionViewItem &option,
											const QModelIndex &index) const
{
	QTimeEdit *editor=new QTimeEdit(parent);
	editor->setDisplayFormat("hh:mm:ss");
	
	return editor;
}
//------------------------------------------------------------------------------
void CTimeEditDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const
{
	QString value=index.model()->data(index, Qt::EditRole).toString();
	
	QTimeEdit *timeEdit=static_cast<QTimeEdit *>(editor);
	timeEdit->setTime(QTime::fromString(value, "hh:mm:ss"));
}
//------------------------------------------------------------------------------
void CTimeEditDelegate::setModelData(	QWidget *editor, QAbstractItemModel *model,
										const QModelIndex &index) const
{
	QTimeEdit *timeEdit=static_cast<QTimeEdit *>(editor);
	QString value=timeEdit->time().toString("hh:mm:ss");
	model->setData(index, value, Qt::EditRole);
}
//------------------------------------------------------------------------------
void CTimeEditDelegate::updateEditorGeometry(	QWidget *editor,
												const QStyleOptionViewItem &option,
	   											const QModelIndex &index) const
{
	editor->setGeometry(option.rect);
}
//------------------------------------------------------------------------------